package com.pro01.backend.controller;

import com.pro01.backend.dto.UserRatioSummaryDTO;
import com.pro01.backend.pojo.PageResult;
import com.pro01.backend.pojo.Result;
import com.pro01.backend.service.AdminRatioService;
import com.pro01.backend.utils.TokenUtil;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/admin/ratios")
public class AdminRatioController {

    @Autowired
    private AdminRatioService adminRatioService;

    @GetMapping
    public Result<PageResult<UserRatioSummaryDTO>> getUserRatioList(@RequestParam(defaultValue = "1") int pageNum,
                                                                    @RequestParam(defaultValue = "10") int pageSize,
                                                                    HttpServletRequest request) {
        if (!"ADMIN".equals(TokenUtil.getRole(request))) {
            return Result.error("无权限访问，仅管理员可用");
        }

        PageResult<UserRatioSummaryDTO> result = adminRatioService.getAllUserRatiosPaged(pageNum, pageSize);
        return Result.success(result);
    }

}
